<template>
  <div class="car-type">
    <slot></slot>
    <section class="years">
      <span
        v-for="(value, key, index) in yearList"
        :key="index"
        @click="change(index)"
        :class="{ active: index === count }"
        >{{ key }}</span
      >
    </section>
    <div>
      <div
        v-for="(value, key, index) in yearList[Object.keys(yearList)[count]]"
        :key="index"
      >
        <h4>
          {{ yearList[Object.keys(yearList)[count]][key][0].exhaust_str }}/
          {{ key }}KW /
          {{ yearList[Object.keys(yearList)[count]][key][0].inhale_type }}
        </h4>
        <!-- exhaust_str -->
        <!-- inhale_type -->
        <ul>
          <li v-for="item in value" @click="changeCarList(item.car_id, item.car_name)" :key="item.car_id">
            {{ item.market_attribute.year }}款{{ item.car_name }}
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { getImageList } from "@/api/carList";
import { mapState } from "vuex";
export default {
  data() {
    return {
      count: 0,
      carInfo: {
        SerialID: this.$route.params.id,
        CarID: "",
        ColorID: ""
      }
    };
  },
  created() {
    console.log(this.yearList);
  },
  computed: {
    ...mapState("CarList", ["yearList"]),
  },
  methods: {
    async init(text) {
      let res = await getImageList({
        ...this.carInfo,
      });
      this.$emit("changeCarListImg", {
        list: res.data.data,
        flag: false,
        text
      })
    },
    change(index) {
      this.count = index;
    },
    changeCarList(id, text) {
      this.carInfo.CarID = id
      this.init(text)
    }
  },
};
</script>

<style lang="scss" scoped>
// 车系颜色
.car-type {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  background: #f4f4f4;
  z-index: 1000;
}

// .car-type > div {
//   width: 100%;
//   height: 100%;
// }
.years {
  width: 100%;
  overflow-x: scroll;
  margin: 8px 0;
  background: #fff;
}
.years span {
  font-size: 16px;
  padding-right: 23px;
  line-height: 38px;
}
.years .active {
  color: #3aacff;
}
.list {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: nowrap;
  flex-wrap: wrap;
  background: #fff;
}
.list li {
  width: 172px;
  font-size: 16px;
  line-height: 34px;
  border: 1px solid #3aacff;
  box-sizing: border-box;
  margin: 10px 0 10px 10px;
  border-radius: 3px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  span:first-child {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin: 0 10px;
    background: #fe9210;
    box-sizing: border-box;
    border: 1px solid #818181;
  }
}
</style>